package com.nantai.jiafang.nantaijiafang.activity.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.view.ViewGroup;

import com.nantai.jiafang.nantaijiafang.zhijian.fragment.Pager_Fragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/9.
 */
public class SectionsPagerAdapter2 extends FragmentPagerAdapter {
    private Context context2;
    private FragmentManager fragmentManager;
    private ArrayList<Pager_Fragment> pager_fragments;
//    private List<String> tagList = new  ArrayList<>();
    public SectionsPagerAdapter2(Context context, FragmentManager fm,ArrayList<Pager_Fragment> pager_fragments) {
        super(fm);
        context2=context;
        this.fragmentManager = fm;
        this.pager_fragments=pager_fragments;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
//        tagList.remove(makeFragmentName(container.getId(), getItemId(position)));//把tag删掉
    }

    @Override
    public Fragment getItem(int position) {
        return pager_fragments.get(position);
    }
    @Override
    public int getCount() {
        // Show 3 total pages.
        return pager_fragments.size();
    }
    public void setPager_fragments(ArrayList<Pager_Fragment> pager_fragments){

//        if(fragmentManager!=null){
//            FragmentTransaction ft = fragmentManager.beginTransaction();
//            for(Fragment f:fragmentManager.getFragments()){
//                ft.remove(f);
//            }
//            ft.commit();
//            ft=null;
//            fragmentManager.executePendingTransactions();
//        }
        this.pager_fragments=pager_fragments;
        notifyDataSetChanged();
    }
    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "";
            case 1:
                return "";
            case 2:
                return "";
        }
        return "";
    }

    private static String makeFragmentName(int viewId, long id) {
        return "android:switcher:" + viewId + ":" + id;
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}